package tests;

import common.AutoTestUtil;
import org.openqa.selenium.By;

import java.io.IOException;

public class PageNoLogin extends AutoTestUtil {

    /**
     * 登录失败测试
     * @throws NoSuchMethodException
     * @throws IOException
     */
    public void failLogin() throws NoSuchMethodException, IOException {
        driver.get("http://47.97.70.52:8081/sign-in.html");
        //获取这里的用户名与密码两个元素
        //错误的用户名
        driver.findElement(By.cssSelector("#username")).sendKeys("张三");
        driver.findElement(By.cssSelector("#password")).sendKeys("zhy19150690517");

        driver.findElement(By.cssSelector("#submit")).click();
        //进行截图操作
        String src = this.getClass().getMethod("failLogin").getName();
        getScreen(src);
        //清空输入框
        driver.findElement(By.cssSelector("#username")).clear();
        driver.findElement(By.cssSelector("#password")).clear();

        //错误的密码
        driver.findElement(By.cssSelector("#username")).sendKeys("朱海洋");
        driver.findElement(By.cssSelector("#password")).sendKeys("zhy");

        driver.findElement(By.cssSelector("#submit")).click();
        getScreen(src);
    }

    /**
     * index列表页，未登录状态
     * @throws IOException
     * @throws NoSuchMethodException
     */
    public void indexNoLogin() throws IOException, NoSuchMethodException {
        driver.get("http://47.97.70.52:8081/index.html");
        String src = this.getClass().getMethod("indexNoLogin").getName();
        getScreen(src);
        //此时会进行跳转，判断登录元素是否存在,设置了隐式等待，所以进行异常捕获
        try {
            driver.findElement(By.cssSelector("body > div > div > div > div:nth-child(1) > div > div.card.card-md > div > h2"));
        }catch (Exception e){
            System.out.println("在indexNoLogin方法里出现异常：" + e);
        }
    }

}
